home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: netcom.com!marnold
- From: marnold@netcom.com (Matt Arnold)
- Subject: Re: Is there a standard for * and & placement style?
- Message-ID: <marnoldDn9u0A.GAD@netcom.com>
- Organization: NETCOM On-line Communication Services (408 261-4700 guest)
- References: <3128BD31.4AF8@wildfire.com> <marnoldDn27q9.Is0@netcom.com> <4gckd5$bc7@clarknet.clark.net> <marnoldDn63vB.H6n@netcom.com> <4gk1b8$mtm@werple.net.au>
- Date: Sat, 24 Feb 1996 08:24:10 GMT
- Sender: marnold@netcom20.netcom.com
-
- davidw@werple.net.au (David White) writes:
-
- >marnold@netcom.com (Matt Arnold) writes:
-
- >>gusty@clark.net (Harlan Messinger) writes:
-
- >>>I think the syntax is dumb in the first place. One declaration statement
- >>>should declare variables of one type. I think
-
- >>> char* a, b, c;
-
- >>>should declare three (char*) variables. If someone also wants a char
- >>>variable d, then that should be on two lines:
-
- >>That would be better, but I still subscribe to the "one concept per
- >>line" theory of programming and would never declare three variables on
- >>a single line.
-
- >The concept used in declarations is that a declaration mimics an
- >expression, e.g., given char *p, if you see *p then it evaluates to a
- >char. The above form is therefore a special case because it can't always
- >be used. In the case of, for example, char (*p)[10], you can't apply it.
- >I can see that in the trivial special cases, like char* foo(), it seems
- >more sensible to some people (foo() returns a char*), but it is an oddity
- >in terms of the general rule.
-
- Hmm, thinking of function foo() as "returning a char*" doesn't seem to me
- to be any more a special case than thinking of p as "_being_ a char*".
-
- I still think pointer-ness or reference-ness is better associated with the
- type. When I see "p" (from your example) in some code, I think of it as
- being type "char*", and that is the way I declare it.
-
- In fact, I'd argue that the fact that a function declaration such as...
-
- char* foo();
-
- ...is a "special case" for the "char *"-style, simply highlights that the
- style, IMO, is conceptually inconsistent. Certainly, the function itself
- doens't have pointer-ness (although, as for as the language it concerned, it
- resovles to an expression that does) and so it doesn't seem quite right to
- associate the * with the function name. It seems inconsistent that you
- would make this concession, but turn around and insist the "char *p" makes
- sense for the declaration of p.
-
- I have never had any inconsistencies like this with the "char*"-style. It
- even, to me, resolves nicely with the fact that you can typedef a "char
- pointer type", PCHAR say, and substitute it for all the char*'s throughout
- the code, whether they be found in casts or declarations or function return
- types.
-
- I don't think there any magic in the fact that C/C++ declarations look
- like expressions. What if, for example, one declared pointer variables
- using a symbol completely different than for dereferencing?
-
- char@ p = // alloc storage to put char "at"
-
- *p = 'x'
-
- It would still make sense to me to think of p's type as "char@", which
- after all *is* its type.
-
-
- I guess it all depends on where you imagine pointer-ness residing: "in"
- the variable, or "in" the type. To me it makes more sense, and actually
- is correct, to think of pointer-ness as a being part of type (we all know
- this is how compilers work). I therefore prefer to write "char* p", not
- "char *p".
-
-
- -------------------------------------------------------------------------
- Matt Arnold | | ||| | |||| | | | || ||
- marnold@netcom.com | | ||| | |||| | | | || ||
- Boston, MA | 0 | ||| | |||| | | | || ||
- 617.389.7384 (h) 617.576.2760 (w) | | ||| | |||| | | | || ||
- C++, MIDI, Win32/95 developer | | ||| 4 3 1 0 8 3 || ||
- -------------------------------------------------------------------------
-
-
-